package com.lnsoft.cac.server.handle.codec.frameMessage;


import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import lombok.Data;
import lombok.NonNull;

@Data
/**
 * 监测数据--日/月 统计数据
 * */
public class VoltageDayMon_Cfm {
    private int Measure_Point_ID;               //1byte             监测点号
    private int Data_Status;                    //1byte             数据发送状态：①0xFF成功②0x00失败

    public ByteBuf toByteBuf() throws Exception{
        if (Data_Status != (byte)0xFF && Data_Status != (byte)0x00) {
            throw new Exception("数据发送状态设置异常");
        }
        if (!Util.measurePointIDIsAvailable(Measure_Point_ID)) {
            throw new Exception("监测点号设置异常");
        }
        ByteBuf bf = Unpooled.buffer();
        bf.writeByte(Measure_Point_ID);
        bf.writeByte(Data_Status);
        return bf;
    }


    //  解析 [监测数据-日月统计确认报文] 帧报文内容区 到消息体中
    public static VoltageDayMon_Cfm decFrameBody(@NonNull byte[] frameBody) throws Exception {

        ByteBuf bf = Unpooled.wrappedBuffer(frameBody);
        VoltageDayMon_Cfm msg = new VoltageDayMon_Cfm();
        int len = frameBody.length;
        if (len == 0) {
            return null;
        }
        if (2 != len) {
            throw new Exception("frameBody 数据异常");
        }
        msg.setMeasure_Point_ID(bf.getUnsignedByte(0));
        msg.setData_Status(bf.getUnsignedByte(1));
        return msg;
    }
}
